package com.example.springbootdemo.user;

import com.example.springbootdemo.validate.el.MultiFieldAssociationCheck;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.Date;

@Data
@MultiFieldAssociationCheck.List(
       value = {
               @MultiFieldAssociationCheck(when = "#type != null && #type.equals('1')", must = "#sendTime != null",message = "当type为定时发送时，必须填写发送时间"),
               @MultiFieldAssociationCheck(when = "#type != null && #type.equals('-1')", must = "#sendContent != null",message = "当type为不是草稿时,sendContent必须有值"),
               @MultiFieldAssociationCheck(when = "#type != null && #type.equals('2')", must = "'123'.equals(#sendContent.content)",message = "当type为立即发送时,sendContent的content属性必须为123")
       }
)
public class MessageCmd {

    @NotEmpty(message = "type不能为空")
    private String type;
 
    //当type为定时发送时，必须填写发送时间，当type为立即发送时，可以不填发送时间
    private Date sendTime;
 
    @Valid
    //当type为草稿时,sendContent可以为空，否则必须有值
    private SendContent sendContent;

    @Data
    public static class SendContent {
//        @NotEmpty
        private String value;
    }
}